//
//  HotCollectCell.m
//  WhereToTravel
//
//  Created by dlios on 15/10/15.
//  Copyright © 2015年 zhoushengmin. All rights reserved.
//

#import "HotCollectCell.h"
#import "HotCityCell.h"
#import "CountryModel.h"

@implementation HotCollectCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}

-  (void)creatView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(WIDTH * 170, HEIGHT * 100);
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 5, 10, 5);
    self.collect = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH * 375, HEIGHT * 230) collectionViewLayout:flowLayout];
    [self.contentView addSubview:self.collect];
    self.collect.delegate = self;
    self.collect.dataSource = self;
    self.collect.scrollEnabled = NO;
    self.collect.backgroundColor = [UIColor clearColor];
    [self.collect registerClass:[HotCityCell class] forCellWithReuseIdentifier:@"collect"];
    
    [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
}
- (void)layoutSubviews {
    [super layoutSubviews];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.hotArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HotCityCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collect" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    CountryModel *model = self.hotArr[indexPath.row];
    [cell.bomImageView sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:[UIImage imageNamed:@"F"]];
    cell.labelcn.text = model.cnname;
    cell.labelen.text = model.enname;
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    CountryModel *model = self.hotArr[indexPath.row];
    [self.delegate send:model.uId];
}
@end
